import * as elIcons from '@element-plus/icons-vue'
import Icon from '/@/components/icon/index.vue'
export function registerIcons(app) {
    /*
     * 全局注册 Icon
     * 使用方式: <Icon name="name" size="size" color="color" />
     * 详见<待完善>
     */
    app.component('Icon', Icon)

    /*
     * 全局注册element Plus的icon
     */
    const icons = elIcons 
    for (const i in icons) {
        app.component(`el-icon-${icons[i].name}`, icons[i])
    }
}

/**
 * 是否是外部链接
 * @param path
 */
export function isExternal(path) {
    return /^(https?|ftp|mailto|tel):/.test(path)
}


// 添加外部连接
export function addExternalEle(items) {
   return  Promise.all(
    items.map(item => {
       return new Promise(r => {
            if(item.classify === 'js') {
                const script = document.createElement('script')
                script.src = item.url
                document.body.appendChild(script)
                script.onload = () => {
                    r()
                }
            } else if(item.classify === 'css') {
    
            }

        })
    })
   )
}

// 获取组件数据
export const getComData =async  (cardJson) => {
    const {
        type = 'static',
        staticData
    } = cardJson
    if(type === 'static') {
        return staticData
    }
}